package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.basic.utils.AppUtil;
import com.baihan.angus.app.game.basic.utils.ComUtil;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.response.ActivityResponse;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class ActivityAdp extends BaseAdp<ActivityResponse, ActivityAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_exhibition_activity, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        int parentWidth = AppUtil.getScreenWidth(BaseApplication.getApplication().getApplicationContext())
                - ComUtil.Dp2Px(BaseApplication.getApplication().getApplicationContext(), 40);
        ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
        layoutParams.width = (parentWidth / 2);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = holder;

        ActivityResponse data = getItem(position);

        vh.tvActivityName.setText(data.getActivityName());
        vh.tvLocation.setText(data.getLocation());
        vh.tvTime.setText(data.getTime());

//        ImageLoader.loadImage(BaseApplication.getApplication().getApplicationContext(),
//                vh.ivActivityPic, data.getUrl(), R.mipmap.ic_test_bg, 0);

        vh.llItem.setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        QMUIRadiusImageView ivActivityPic;
        TextView tvActivityName, tvLocation, tvTime;
        LinearLayout llItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivActivityPic = itemView.findViewById(R.id.ivActivityPic);
            tvActivityName = itemView.findViewById(R.id.tvActivityName);
            tvLocation = itemView.findViewById(R.id.tvLocation);
            tvTime = itemView.findViewById(R.id.tvTime);
            llItem = itemView.findViewById(R.id.llItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
